import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/common/xindong_methods.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:xindong/routes/user/wallet/xindong_wallet_ctr.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/common/xindong_button.dart';
import 'package:xindong/widgets/common/xindong_common_widget.dart';

class XinDongWalletAccountYeMian extends StatefulWidget {
  const XinDongWalletAccountYeMian({super.key});

  @override
  State<XinDongWalletAccountYeMian> createState() => _XinDongWalletAccountYeMianState();
}

class _XinDongWalletAccountYeMianState extends State<XinDongWalletAccountYeMian> {
  final TextEditingController nameController =
      TextEditingController(text: XinDongUserController.to.userInfo?.zhifuname ?? "");
  final TextEditingController accountController =
      TextEditingController(text: XinDongUserController.to.userInfo?.zhifucount ?? "");

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XinDongAppBar("支付宝账号"),
      body: GestureDetector(
        onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
        child: ListView(
          children: [
            Container(
              width: double.infinity,
              height: kCellHeight,
              color: DZColors.cellColor,
              padding: const EdgeInsets.only(left: kPaddingValue, right: kPaddingValue),
              child: Row(
                children: [
                  const Text(
                    "支付宝姓名",
                    style: TextStyle(color: DZColors.titleColor, fontSize: 16),
                  ),
                  Expanded(
                    child: TextField(
                      controller: nameController,
                      keyboardType: TextInputType.text,
                      maxLines: 1,
                      style: const TextStyle(fontSize: 16, color: DZColors.titleColor),
                      decoration: const InputDecoration(
                        border: InputBorder.none,
                        hintText: '请输入姓名',
                        hintStyle: TextStyle(fontSize: 16, color: DZColors.placeholderColor),
                        // 设置这个之后，居中
                        contentPadding: EdgeInsets.fromLTRB(20, 16, 20, 16),
                      ),
                    ),
                  ),
                ],
              ),
            ),
            commonDivider(),
            Container(
              width: double.infinity,
              height: kCellHeight,
              color: DZColors.cellColor,
              padding: const EdgeInsets.only(left: kPaddingValue, right: kPaddingValue),
              child: Row(
                children: [
                  const Text(
                    "支付宝账号",
                    style: TextStyle(color: DZColors.titleColor, fontSize: 16),
                  ),
                  Expanded(
                    child: TextField(
                      controller: accountController,
                      keyboardType: TextInputType.text,
                      maxLines: 1,
                      style: const TextStyle(fontSize: 16, color: DZColors.titleColor),
                      decoration: const InputDecoration(
                        border: InputBorder.none,
                        hintText: '请输入账号',
                        hintStyle: TextStyle(fontSize: 16, color: DZColors.placeholderColor),
                        // 设置这个之后，居中
                        contentPadding: EdgeInsets.fromLTRB(20, 16, 20, 16),
                      ),
                    ),
                  ),
                ],
              ),
            ),
            const Padding(
              padding: EdgeInsets.all(16.0),
              child: Text(
                "温馨提示：为保证提现及时有效到账，需要确保填写姓名的与账号的一致性。",
                style: TextStyle(color: DZColors.contentColor, fontSize: 14),
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: 80),
              padding: const EdgeInsets.only(left: kPaddingValue, right: kPaddingValue),
              width: double.infinity,
              height: kButtonHeight,
              child: XinDongCommonButton(
                "绑定",
                onTap: () async {
                  bool result = await XinDongWalletCtr.to.requestBindingZ(
                    name: nameController.text.trim(),
                    account: accountController.text.trim(),
                  );
                  if (result) {
                    FocusScope.of(currentContext()).requestFocus(FocusNode());
                    Get.back();
                    XinDongUserController.to.requestUserInfo();
                  }
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
